#include "../include/Equation.h"

#define beta 11.5 / 180 * PI

double l = 89, h = 49;
double A, B, C, E;

double f(double alpha)
{
    return A * sin(alpha) * cos(alpha) + B * sin(alpha) * sin(alpha) - C * cos(alpha) - E * sin(alpha);
}

double g(double alpha)
{
    return A * (cos(alpha) * cos(alpha) - sin(alpha) * sin(alpha)) + 2 * B * sin(alpha) * cos(alpha) + C * sin(alpha) - E * cos(alpha);
}

int main()
{
    A = l * sin(beta);
    B = l * cos(beta);

    double D = 50;
    C = (h + 0.5 * D) * sin(beta) - 0.5 * D * tan(beta);
    E = (h + 0.5 * D) * cos(beta) - 0.5 * D;

    //(1)
    Newton first_solver(f, g);
    cout << "(1):" << endl;
    cout << first_solver.solve(0, PI / 2) << endl;
    cout << f(first_solver.solve(0, PI / 2)) << endl;

    D = 30;
    C = (h + 0.5 * D) * sin(beta) - 0.5 * D * tan(beta);
    E = (h + 0.5 * D) * cos(beta) - 0.5 * D;

    //(2)
    cout << endl;
    cout << "(2):" << endl;
    Newton second_solver(f, g);
    cout << second_solver.solve(0, PI / 2) << endl;
    cout << f(second_solver.solve(0, PI / 2)) << endl;

    //(3)
    cout << endl;
    cout << "(3):" << endl;
    cout << "Far:" << endl;
    Secant third_solver(f);
    cout << third_solver.solve(0, PI / 10) << endl;
    cout << f(third_solver.solve(0, PI / 10)) << endl;

    cout << "Close:" << endl;
    cout << third_solver.solve(0, PI / 4) << endl;
    cout << f(third_solver.solve(0, PI / 4)) << endl;

    return 0;
}